package com.biggabrotha {
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;

	import mx.containers.Canvas;
	import mx.controls.Image;

	public class DummyPictureProviderNetwork extends Canvas implements PictureProvider {
		private static const netcheckurl:String="http://www.stud.uni-karlsruhe.de/~uekz/MMALIENX_klien.gif";

		[Embed(source="../assets/MMALIENX_klien.gif")]
		private static const untestedImageClass:Class;
		[Embed(source="../assets/rj45-1.png")]
		private static const networkFailedImageClass:Class;
		private var _isWorking:Boolean;

		public function get isWorking():Boolean {
			return _isWorking
		}
		public static const img:Image=new Image()

		private static var loader:Loader

		public function DummyPictureProviderNetwork() {
			super();
			img.source=untestedImageClass
			this.addChild(img)
			this.createChildren()
			this.addEventListener(Event.ADDED_TO_STAGE, addedToStage)
			this.addEventListener(Event.REMOVED_FROM_STAGE, removedFromStage)
		}

		private function removedFromStage(e:Event) {
			loader=null
		}

		private function addedToStage(e:Event=null) {
			//  super.addedToStage(e);
			loader=new Loader()
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded)
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, failed)
			loader.load(new URLRequest(encodeURI(netcheckurl)));
		}

		private function loaded(e:Event):void {
			img.source=e.currentTarget.content
			_isWorking=true
		}

		private function failed(e:Event):void {
			img.source=networkFailedImageClass
			_isWorking=false
		}
	}
}